package com.hnu.web;

import org.apache.struts2.ServletActionContext;

import com.hnu.model.Bookmark;
import com.hnu.model.User;

public class ExternLinkBean extends BaseAction {

	private static final long serialVersionUID = 5251808116168600833L;
	private String username;
	private String password;
	private String title;
	private String url;
	private String descrip;
	private String message;
	
	public String addExternBookmark()
	{
		User user = this.servLocator.getUserServ().verifyLogin(this.username);
		if((user != null) && (user.getPassword().equals(this.password)))
		{
			if (this.title == null
					|| this.title.trim().isEmpty()
					|| this.descrip == null
					|| this.descrip.trim().isEmpty()
					|| this.url == null
					|| this.url.trim().isEmpty()) {
				this.message = "所有数据不允许为空！";

			} else {
				Bookmark bookmark = new Bookmark();
				bookmark.setBookmarkDesc(this.descrip.trim());
				bookmark.setBookmarkTitle(this.title.trim());
				bookmark.setBookmarkUrl(this.url.trim());
				long userId = user.getUserId();
				String indexPath = ServletActionContext.getRequest().getRealPath(
						"/")
						+ "indexPath";
				if(this.servLocator.getBookmarkServ().addBookmark(userId, bookmark,
						indexPath))
				{
					this.message = "收藏成功！";
				}
				else
				{
					this.message = "您已收藏过该书签！";
				}
			}
		}
		else
		{
			setMessage("用户名或者密码错误！");
		}
		return "success";
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getDescrip() {
		return descrip;
	}

	public void setDescrip(String descrip) {
		this.descrip = descrip;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getMessage() {
		return message;
	}

}
